﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace TankDemo
{
    public partial class FormLogin : Form
    {






        public FormLogin()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormLogin_Load(object sender, EventArgs e)
        {
            LoginPanel.SetBounds(0, 0, 800, 600);
            panel10.SetBounds(12, 52, 542, 499);
            SelectA.SetBounds(12, 52, 542, 499);
            SelectB_E.SetBounds(12, 52, 542, 499);
            SelectB.SetBounds(12, 52, 542, 499);
            SelectB_Defen.SetBounds(12, 52, 542, 499);
            SelectB_D.SetBounds(12, 52, 542, 499);
            SelectD.SetBounds(12, 52, 542, 499);
            SelectC.SetBounds(12, 52, 542, 499);



            SelectB_C.SetBounds(13, 12, 516, 473);
            SelectB_D.SetBounds(13, 12, 516, 473);
            SelectB_B.SetBounds(13, 12, 516, 473);
            SelectB_A.SetBounds(13, 12, 516, 473);
            SelectB_F.SetBounds(13, 12, 516, 473);
            panelVisible(1);






            lblShowDay.Text = GetNowTimeDay();
            new Thread(() =>
            {
                while (true)
                {
                    try { lblShowTime.BeginInvoke(new MethodInvoker(() => lblShowTime.Text = DateTime.Now.ToString("HH:mm:ss"))); }

                    catch { }

                    Thread.Sleep(1000);

                }

            }).Start();

            SelectB_E.Visible = false;

            //查询列表
            //SelThemes();
        }

        /// <summary>
        /// 显示日期
        /// </summary>
        string GetNowTimeDay()
        {
            var date = DateTime.Now;
            string dayInfo = $"{date.Year}年{date.Month}月{date.Day}日 {DayOfWeek()}";

            return dayInfo;
        }

        /// <summary>
        /// 返回日期几
        /// </summary>
        /// <returns></returns>
        public string DayOfWeek()
        {
            string week = "";
            switch (DateTime.Now.DayOfWeek.ToString("D"))
            {
                case "0":
                    week = "星期日 ";
                    break;
                case "1":
                    week = "星期一 ";
                    break;
                case "2":
                    week = "星期二 ";
                    break;
                case "3":
                    week = "星期三 ";
                    break;
                case "4":
                    week = "星期四 ";
                    break;
                case "5":
                    week = "星期五 ";
                    break;
                case "6":
                    week = "星期六 ";
                    break;
            }
            return week;
        }

        /// <summary>
        /// 关闭窗体
        /// </summary>
        private void FormLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("真的要退出程序吗？", "退出程序", MessageBoxButtons.YesNo) == DialogResult.Yes)

            {
                Application.Exit();
                System.Environment.Exit(0);

            }

            else

            {

                e.Cancel = true;

            }
        }

        private void FormLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (MessageBox.Show("真的要退出程序吗？", "退出程序", MessageBoxButtons.YesNo) == DialogResult.Yes)

            {
                Application.Exit();
                System.Environment.Exit(0);

            }

            else
            {
                return;
            }
        }


        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void loginBut_Click(object sender, EventArgs e)
        {
            
            DbHelperMySQL db = new DbHelperMySQL();
            //登陆

            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from usertab where account='" + textBox1.Text + "' and password='" + textBox2.Text + "'");
            if (dt.Read())
            {
                string userid = dt.GetString(0);
                daojishiLabel.Text = userid;
                LoginPanel.Visible = false;
                //显示首页
                panelVisible(5);


                if (textBox1.Text == "admin") {
                    button22.Visible = true;
                    button23.Visible = true;
                }

            }
            else
            {
                daojishiLabel.Text = "登陆失败";
            }
            
            
        }
       

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private string imgurl = "http://39.97.172.34:8080/";

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeView treeView = sender as TreeView;
            TreeNode tn = treeView.SelectedNode;


            // themes[int.Parse(this.Tag.ToString())].list[tn1.Tag].topic_img

            if ( tn.Tag.ToString()!="") { 
                if(tn.Level == 0) {
                    pictureBox3.ImageLocation = imgurl + themes[int.Parse(tn.Tag.ToString())].bookImg;
                }
                if (tn.Level == 1)
                {
                    pictureBox3.ImageLocation = imgurl + tn.Tag;
                }
            }
        }
        /// <summary>
        /// 切换按钮颜色
        /// </summary>
        /// <param name="button"></param>
        private void butBackColor(Button button) {

            button1.BackColor = Color.FromArgb(8, 46, 66);
            button2.BackColor = Color.FromArgb(8, 46, 66);
            button3.BackColor = Color.FromArgb(8, 46, 66);
            button4.BackColor = Color.FromArgb(8, 46, 66);
            button.BackColor = Color.FromArgb(0, 188, 255);
        }
        private List<Theme> themes = new List<Theme>();
        private int themeDefnum = 0;
        private void SelThemes(int tankeid)
        {

            Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
            List<Dictionary<string, List<string>>> list = new List<Dictionary<string, List<string>>>();

            themes.Clear();


            for (int i = 0; i < 100; i++)
            {
                themes.Add(new Theme());
            }

            DbHelperMySQL db = new DbHelperMySQL();
            //登陆

            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from theme where type="+ selTankeType + " and tankeid="+tankeid);
            while (dt.Read())
            {
                Theme t = new Theme();
                t.id = int.Parse((dt.GetString("id")));
                t.title = dt.GetString("title");
                t.bookImg = dt.GetString("bookImg") ;
                themes[t.id] = t;
                if (themeDefnum == 0) {
                    themeDefnum = t.id;
                }

            }

            dt = db.ExecuteReader("select * from topic");
            while (dt.Read())
            {
                Topic topic = new Topic();
                topic.theme_id = int.Parse(dt.GetString("theme_id"));
                topic.title = dt.GetString("title");
                topic.id = int.Parse((dt.GetString("id")));
                topic.title_id = int.Parse(dt.GetString("title_id"));
                topic.topic_img = dt.GetString("topic_img")==null?"": dt.GetString("topic_img");

                themes[topic.theme_id].list.Add(topic);
            }
            
            treeView1.Nodes.Clear();
            for (int i = 0; i < themes.Count; i++)
            {

                Theme theme = themes[i];
                if (theme.id != 0)
                {
                   
                    TreeNode tn = new TreeNode();
                    tn.Tag = i;
                    tn.Text = theme.title;
                    for (int j = 0; j < theme.list.Count; j++)
                    {
                        TreeNode tn1 = new TreeNode();
                        tn1.Tag = theme.list[j].topic_img;
                        tn1.Text = theme.list[j].title;
                        tn.Nodes.Add(tn1);
                    }

                    treeView1.Nodes.Add(tn);
                }
            }


        }
        //选择坦克类型（第一选项 与第四选项内容不同）
        private int selTankeType = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            //切换按钮颜色
            butBackColor(sender as Button);
            selTankeType = 0;
            //选择坦克类型
            Seltanke();


           
            //文档
            panelVisible(2);


        }
        /// <summary>
        /// 选择坦克类型  开始阅读
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button25_Click(object sender, EventArgs e)
        {
            if ("请选择坦克类型" != comboBox3.Text) {
                themeDefnum = 0;
                //查询列表
                SelThemes(tankeDict[comboBox3.Text].id);
                SelectA_1.Visible = false;
                pictureBox3.ImageLocation = imgurl + themes[themeDefnum].bookImg;

            }
            else
            {
                MessageBox.Show("请选择坦克类型");
            }
            

        }


        private Dictionary<string, Tanke> tankeDict = new Dictionary<string, Tanke>();
        private void Seltanke() {

            comboBox3.Items.Clear();
            comboBox5.Items.Clear();
            DbHelperMySQL db = new DbHelperMySQL();
            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from tanketab ");
            while (dt.Read())
            {
                Tanke t = new Tanke();
                t.id = int.Parse((dt.GetString("id")));
                t.title = dt.GetString("title");
                comboBox3.Items.Add(t.title);
                comboBox5.Items.Add(t.title);
                if (!tankeDict.ContainsKey(t.title)) { 
                    tankeDict.Add(t.title, t);
                }
            }
            comboBox3.Text = "请选择坦克类型";
            comboBox5.Text = "请选择坦克类型";
        }

        
        private int thisQuestionIndex = 0;
        private int thisQuestionMax = 0;
        private List<Question> QuestionList =new List<Question>();

        private void SelQuestion(int s) {
           
            //
            s = s % QuestionList.Count;
            thisQuestionIndex = s;
            if (QuestionList[s].opt == 0) { 
                label3.Text = "1、单选题（共"+selSum+"题）";
                label4.Text = (s + 1) + "、 " + QuestionList[s].question;
                label5.Text = "A、" + QuestionList[s].optsA;
                label6.Text = "B、" + QuestionList[s].optsB;
                label7.Text = "C、" + QuestionList[s].optsC;
                label8.Text = "D、" + QuestionList[s].optsD;

                panel11.Visible = false;
                panel13.Visible = false;

                panel6.Visible = true;
                panel7.Visible = true;
                panel8.Visible = true;
                panel9.Visible = true;
            }
            else
            {
                label3.Text = "2、判断题（共" + judSum + "题）";
                label4.Text = (s + 1- selSum) + "、 " + QuestionList[s].question;

                panel11.Visible = true;
                panel13.Visible = true;

                panel6.Visible = false;
                panel7.Visible = false;
                panel8.Visible = false;
                panel9.Visible = false;
            }

            label5.Tag = "A";
            label6.Tag = "B";
            label7.Tag = "C";
            label8.Tag = "D";

            label10.Tag = "1";
            label12.Tag = "0";

            panel6.Tag = "A";
            panel7.Tag = "B";
            panel8.Tag = "C";
            panel9.Tag = "D";
            panel11.Tag = "1";
            panel13.Tag = "0";



            if (s == 0)
            {
                button5.Visible = false;
            }
            else
            {
                button5.Visible = true;
            }

            if (s == QuestionList.Count-1)
            {
                button6.Visible = false;
            }
            else
            {
                button6.Visible = true;
            }

        }
        private void UpQuestion() {
            if (thisQuestionIndex> 0)
            {
                button5.Visible = true;
                button6.Visible = true;
                thisQuestionIndex -= 1;
                SelQuestion(thisQuestionIndex);
            }
            else
            {
                button5.Visible = false;
            }
        }
        private void DownQuestion()
        {
            if (thisQuestionIndex < QuestionList.Count-1)
            {
                button6.Visible = true;
                button5.Visible = true;
                thisQuestionIndex += 1;
                SelQuestion(thisQuestionIndex);
            }
            else
            {
                button6.Visible = false;
            }
        }

       private int selSum = 0;
       private int selMark = 0;
        private int judSum = 0;
        private int judMark =0;

        private void SelSqlQuestion(int type) {
            DbHelperMySQL db = new DbHelperMySQL();


            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from Questionsettab");
            if (dt.Read())
            {
                 selSum = int.Parse(dt.GetString("selSum"));
                 selMark = int.Parse(dt.GetString("selMark"));
                 judSum = int.Parse(dt.GetString("judSum"));
                 judMark = int.Parse(dt.GetString("judMark"));
            }

            List<Question> listA = new List<Question>();
            List<Question> listB = new List<Question>();
            QuestionList.Clear();
            dt = db.ExecuteReader("select * from Questiontab where type="+ type);
            while (dt.Read())
            {
                Question t = new Question();
                t.id = int.Parse(dt.GetString("id"));
                t.type = int.Parse(dt.GetString("type"));
                t.question = dt.GetString("question");
                t.opt = int.Parse(dt.GetString("opt"));
                t.answer = dt.GetString("answer");
                if (t.opt == 0)
                {
                    t.optsA = dt.GetString("optsA")==null?"": dt.GetString("optsA");
                    t.optsB = dt.GetString("optsB") == null ? "" : dt.GetString("optsB");
                    t.optsC = dt.GetString("optsC") == null ? "" : dt.GetString("optsC");
                    t.optsD = dt.GetString("optsD") == null ? "" : dt.GetString("optsD");
                    t.fs = selMark;
                    listA.Add(t);
                }
                else if (t.opt == 1)
                {
                    t.fs = judMark;
                    listB.Add(t);
                }
                else if (t.opt == 2)
                {
                    t.optsA = dt.GetString("optsA") == null ? "" : dt.GetString("optsA");
                    t.optsB = dt.GetString("optsB") == null ? "" : dt.GetString("optsB");
                    t.fs = judMark;
                    listB.Add(t);
                }


            }



            Random r = new Random();
           int rr= r.Next(0, listA.Count);
            if (listA.Count < selSum) { selSum = listA.Count; }
            for (int i = 0; i < selSum; i++)
            {
                QuestionList.Add(listA[rr]);
                listA.RemoveAt(rr);
                rr = r.Next(0, listA.Count);
            }

            rr = r.Next(0, listB.Count);
            if (listB.Count < judSum) { judSum = listB.Count; }
            for (int i = 0; i < judSum; i++)
            {
                QuestionList.Add(listB[rr]);
                listB.RemoveAt(rr);
                rr = r.Next(0, listB.Count );
            }



            SelQuestion(0);
        }





        private void button2_Click(object sender, EventArgs e)
        {
            
            butBackColor(sender as Button);
            SelectB_A.Visible = false;
            SelectB_B.Visible = false;
            SelectB_D.Visible = false;
            SelectB_C.Visible = false;
            SelectB_F.Visible = false;
            //题库类型
            panelVisible(3);
           


        }

        private void button3_Click(object sender, EventArgs e)
        {
            butBackColor(sender as Button);
            panelVisible(8);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            butBackColor(sender as Button);
            SelectD_A.Visible = false;
            SelectD_B.Visible = false;
            panelVisible(7);
        }


        private void button5_Click(object sender, EventArgs e)
        {
            UpQuestion();
            SelButBackColor(QuestionList[thisQuestionIndex].clickPanel);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            DownQuestion();
            SelButBackColor(QuestionList[thisQuestionIndex].clickPanel);
        }





        /// <summary>
        /// 切换按钮颜色
        /// </summary>
        /// <param name="panel"></param>
        private void SelButBackColor(Panel panel)
        {
            QuestionList[thisQuestionIndex].clickPanel = panel;
            


            panel6.BackgroundImage = Properties.Resources.选择框2;
            panel7.BackgroundImage = Properties.Resources.选择框2;
            panel8.BackgroundImage = Properties.Resources.选择框2;
            panel9.BackgroundImage = Properties.Resources.选择框2;

            panel11.BackgroundImage = Properties.Resources.选择框2;
            panel13.BackgroundImage = Properties.Resources.选择框2;
            if (panel !=null) { 
                panel.BackgroundImage = Properties.Resources.选择框1;
                QuestionList[thisQuestionIndex].selanswer = panel.Tag as String;
            }
        }
        private void label5_MouseClick(object sender, MouseEventArgs e)
        {
            SelButBackColor((sender as Label).Parent as Panel);
        }

        private void panel6_MouseClick(object sender, MouseEventArgs e)
        {
            SelButBackColor(sender as Panel);
        }

        private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
        {
            for (int i = 0; i < treeView1.Nodes.Count; i++)
            {
                if (treeView1.Nodes[i] != treeView1.SelectedNode)
                {
                    treeView1.Nodes[i].Collapse(true);
                }
            }
        }

        /// <summary>
        /// 显示开始答题
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button7_Click(object sender, EventArgs e)
        {
            MessageBox.Show("开发中");
           
        }
        private int buttNum = 2;
        private void button8_Click(object sender, EventArgs e)
        {
            button13.Text = "完成测试";
            buttNum = 2;
            SelTanketu();
            SelectB_A.Visible = true;

        }
        private Dictionary<string, Tanke> dictTanke = new Dictionary<string, Tanke>();
        Dictionary<string, string> dict = new Dictionary<string, string>();
        private void SelTanketu(int n = 0)
        {
            pictureBox1.Image = null;
            comboBox1.Items.Clear();

            dictTanke = new Dictionary<string, Tanke>();
            dict = new Dictionary<string, string>();



            DbHelperMySQL db = new DbHelperMySQL();

            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from tanketab");
            while (dt.Read())
            {
                Tanke t = new Tanke();
                t.id = int.Parse((dt.GetString("id")));
                t.title = dt.GetString("title");
                dictTanke.Add(t.id.ToString(), t);
                comboBox1.Items.Add(t.title);
                dict.Add(t.title, t.id.ToString());


            }

            dt = db.ExecuteReader("select * from tanketu");
            while (dt.Read())
            {
                Tanketu t = new Tanketu();
                t.tankeid = int.Parse(dt.GetString("tankeid"));
                t.title= dt.GetString("title");
                t.img = dt.GetString("img");
                t.id = int.Parse((dt.GetString("id")));
                if (dictTanke.ContainsKey(t.tankeid.ToString())) { 
                    dictTanke[t.tankeid.ToString()].tanketus.Add(t);
                }

            }
            dt.Close();


        }

        private void panelVisible(int n) {
            //登陆页面
            LoginPanel.Visible = false;
            //文档
            SelectA.Visible = false;
            //题库类型
            SelectB.Visible = false;
            //题库
            SelectB_E.Visible = false;
            //首页
            panel10.Visible = false;
            //得分
            SelectB_Defen.Visible = false;

            SelectD.Visible = false;

            SelectC.Visible = false;

            switch (n) {
                case 1:
                    LoginPanel.Visible = true;
                    break;
                case 2:
                    SelectA_1.Visible = true;
                    SelectA.Visible = true;
                    break;
                case 3:
                    SelectB_B.Visible = false;
                    SelectB.Visible = true;
                    break;
                case 4:
                  
                    SelectB_E.Visible = true;

                    break;
                case 5:
                    panel10.Visible = true;
                    break;
                case 6:
                    SelectB_Defen.Visible = true;
                    break;
                case 7:
                    SelectD.Visible = true;
                    break;
                case 8:
                    SelectC.Visible = true;
                    break;

            }

        }

        private void button9_Click(object sender, EventArgs e)
        {
           
           
            defen();

            //thisQuestionIndex += 1;
            //SelQuestion(thisQuestionIndex);
        }
private void but_Click(object sender, EventArgs e)
        {

            thisQuestionIndex = 0;
            SelQuestion(thisQuestionIndex);
            panelVisible(4);
        }

        //考试得分页面显示
        private void defen() {

            bool b = false;
            int df = 0;
            for (int i = 0; i < QuestionList.Count; i++)
            {
                b = QuestionList[i].answer == QuestionList[i].selanswer;
                if (b) { df += QuestionList[i].fs; }
                Button button = new Button();
                button.Width = 27;
                button.Height = 27;
                button.ForeColor = Color.White;
                
                if (i < selSum)
                {
                   
                    button.Location = new Point((i % 10) * 30+40, 30 * (i / 10)+240);
                    
                    button.Text = i.ToString();
                    if (!b) {
                        button.BackColor = Color.Red;
                    }
                    button.Click += but_Click;



                   
                }
                else {
                    int j = i - selSum;
                    button.Location = new Point((j % 10) * 30+40, 30 * (j / 10)+340);
                    button.Text = j.ToString();
                    if (!b)
                    {
                        button.BackColor = Color.Red;
                    }
                    button.Click += but_Click;
                }
                SelectB_Defen.Controls.Add(button);




            }

            label14.Text = df + "分";

            timer1.Enabled = false;
            DateTime dt = DateTime.Now.AddMinutes(30);
            DfTimlabel.Text = "选择题" + selSum + " 判断题" + judSum + " 答题时间" + (dt - kaoshiDateTime).Minutes + ":" + (dt - kaoshiDateTime).Seconds;


            
            panelVisible(6);

        }


        private void textBox1_Enter(object sender, EventArgs e)
        {
            if (textBox1.Text == "输入用户名") { textBox1.Text = ""; }
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            if (textBox1.Text == "") { textBox1.Text = "输入用户名"; }
        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            if (textBox2.Text == "输入密码") { textBox2.Text = ""; }
        }

        private void textBox2_Leave(object sender, EventArgs e)
        {
            if (textBox2.Text == "") { textBox2.Text = "输入密码"; }
        }


        private DateTime kaoshiDateTime;

        private void button11_Click(object sender, EventArgs e)
        {

            kaoshiDateTime = DateTime.Now.AddMinutes(30); ;
            timer1.Enabled = true;


          

            //题库
            panelVisible(4);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            DateTime dt = DateTime.Now;
           
            if (dt > kaoshiDateTime) {
                timer1.Enabled = false;
                //考试时间结束
                defen();
            }
            else
            {
                daojishiLabel.Text = "剩余考试时间："+(kaoshiDateTime-dt ).Minutes + ":" + (kaoshiDateTime-dt).Seconds;
            }
       
        }


        private List<Tanketu> tlist = new List<Tanketu>();
        private int tkindex = 0;
        private void button13_Click(object sender, EventArgs e)
        {
            if (buttNum==3) {
                SelectB_F.Visible = true;
                SelectB_D.Visible = false;
            }
          

           

        }


        /// <summary>
        /// 上一步
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button14_Click(object sender, EventArgs e)
        {
            if (tkindex == 0) { } else {
                tkindex -= 1;
                pictureBox4.ImageLocation = imgurl + tlist[tkindex].img;
                button15.Visible = true;
                button13.Visible = false;
                button14.Visible = true;
                   

                label23.Text = tlist[tkindex].title;
            }
        }
        /// <summary>
        /// 下一步
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button15_Click(object sender, EventArgs e)
        {
            if (tkindex>tlist.Count-2) {
                button15.Visible = false;
                button13.Visible = true;
                button14.Visible = false;
            }
            else
            {
                tkindex += 1;
                pictureBox4.ImageLocation = imgurl + tlist[tkindex].img;
                label23.Text = tlist[tkindex].title;
                    }
        }

        private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
        {

        }

        private void button16_Click(object sender, EventArgs e)
        {


            if (comboBox2.Text == "图示分析")
            {

                if (comboBox1.SelectedItem != null)
                {
                   
                    tlist = dictTanke[dict[comboBox1.SelectedItem.ToString()]].tanketus;

                    tkindex = 0;
                    pictureBox4.ImageLocation = imgurl+ tlist[tkindex].img;
                    label23.Text = tlist[tkindex].title;
                    //显示开始答题
                    SelectB_D.Visible = true;
                    SelectB_A.Visible = false;
                    SelectB_C.Visible = false;

                    button13.Visible = false;
                    button14.Visible = true;
                    button15.Visible = true;
                }
            }
            else if (comboBox2.Text == "液压系统解答") {
                //显示开始答题
                SelectB_C.Visible = true;
                SelectB_A.Visible = false;
                SelectB_D.Visible = false;

                button13.Visible = false;
                button14.Visible = true;
                button15.Visible = true;
            }
        }

        private void panel4_Paint(object sender, PaintEventArgs e)
        {

        }

        /// <summary>
        /// 监测实操训练
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button17_Click(object sender, EventArgs e)
        {
            button13.Text = "检测数据";
            buttNum = 3;
            SelTanketu();
            SelectB_A.Visible = true;
        }

        private void button20_Click(object sender, EventArgs e)
        {

            /*
             selTankeType = 1;
             //选择坦克类型
             Seltanke();
             //文档
             panelVisible(2);
            */


            //提前查询题库内容
            SelSqlQuestion(int.Parse((sender as Button).Tag.ToString()));

            label16.Text = "选择题" + selSum + "  判断题" + judSum + " 答题时间30分钟";



            //显示开始答题
            SelectB_B.Visible = true;

        }

        private void button21_Click(object sender, EventArgs e)
        {
            selTankeType = 2;
            //选择坦克类型
            Seltanke();
            //显示选择坦克
            SelectD_A.Visible = true;
            SelectD_B.Visible = false;
        }

        private void button22_Click(object sender, EventArgs e)
        {
            FromMain fromMain = new FromMain();
            fromMain.Show();
        }

        private void button23_Click(object sender, EventArgs e)
        {
            FormQuestion formQuestion = new FormQuestion();
            formQuestion.Show();
        }

        private void button18_Click(object sender, EventArgs e)
        {
            MessageBox.Show("开发中");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            MessageBox.Show("开发中");
        }

        private void button12_Click(object sender, EventArgs e)
        {
            MessageBox.Show("压力脉动： 2.1%BSL\n压力传感器量：34Mpa\n污染度评估等级：一般\n油液还剩5L、可运转8小时");
        }

        private void button19_Click(object sender, EventArgs e)
        {
            MessageBox.Show("油压测试正常、请保持！");
        }

        private void button24_Click(object sender, EventArgs e)
        {
            MessageBox.Show("压力脉动： 2.1%BSL\n压力传感器量：34Mpa\n 可正常运转32天");
        }



        private int selpandingIndex;
        private void button26_Click(object sender, EventArgs e)
        {




            DbHelperMySQL db = new DbHelperMySQL();

            QuestionList.Clear();
            MySql.Data.MySqlClient.MySqlDataReader dt = db.ExecuteReader("select * from Questiontab where opt=2 and  type=0" );
            while (dt.Read())
            {
                Question t = new Question();
                t.id = int.Parse(dt.GetString("id"));
                t.type = int.Parse(dt.GetString("type"));
                t.question = dt.GetString("question");
                t.opt = int.Parse(dt.GetString("opt"));
                t.answer = dt.GetString("answer");
               
                t.optsA = dt.GetString("optsA") == null ? "" : dt.GetString("optsA");
                t.optsB = dt.GetString("optsB") == null ? "" : dt.GetString("optsB");
                t.fs = judMark;
                QuestionList.Add(t);
            }
            selpandingIndex=0;
            button27.Text = QuestionList[selpandingIndex].optsA;
            button28.Text = QuestionList[selpandingIndex].optsB;

            //隐藏选择坦克
            SelectD_A.Visible = false;
            //显示答题列表
            SelectD_B.Visible = true;


            //查询
        }

        private void SelectD_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button27_Click(object sender, EventArgs e)
        {
            if (QuestionList[selpandingIndex].answer == "A") {
                selpandingIndex += 1;
                if (selpandingIndex < QuestionList.Count) { 
                    button27.Text = QuestionList[selpandingIndex].optsA;
                    button28.Text = QuestionList[selpandingIndex].optsB;
                }
                else
                {
                    selpandingIndex--;
                    MessageBox.Show("以完成训练！");
                }

            }
        }

        private void button28_Click(object sender, EventArgs e)
        {
            if (QuestionList[selpandingIndex].answer == "B")
            {
                selpandingIndex += 1;
                if (selpandingIndex < QuestionList.Count)
                {
                    button27.Text = QuestionList[selpandingIndex].optsA;
                    button28.Text = QuestionList[selpandingIndex].optsB;
                }
                else
                {
                    selpandingIndex--;
                    MessageBox.Show("以完成训练！");
                }
            }
        }
    }
}
